package util;

import java.util.Date;

/**
 * 出行记录实体类，记录用户的绿色出行信息
 */
public class TravelRecord {
    private int id;
    private int userId;
    private Date travelDate;
    private String travelType; // 公交、地铁、共享单车等
    private String startLocation;
    private String endLocation;
    private double distance; // 出行距离，单位：公里
    private int earnedPoints; // 获得的积分
    private double carbonReduction; // 减少的碳排放量，单位：kg

    // 构造函数
    public TravelRecord() {
    }

    public TravelRecord(int userId, Date travelDate, String travelType, String startLocation,
            String endLocation, double distance) {
        this.userId = userId;
        this.travelDate = travelDate;
        this.travelType = travelType;
        this.startLocation = startLocation;
        this.endLocation = endLocation;
        this.distance = distance;
        calculatePointsAndCarbonReduction();
    }

    /**
     * 根据出行方式和距离计算积分和碳减排量
     */
    private void calculatePointsAndCarbonReduction() {
        switch (travelType) {
            case "共享单车":
            case "自行车":
                earnedPoints = (int) Math.ceil(distance); // 骑行1公里积1分
                carbonReduction = distance * 0.2; // 骑行1公里减少0.2kg碳排放
                break;
            case "公交":
                earnedPoints = 2; // 乘坐公交1次积2分
                carbonReduction = 0.5; // 公交出行1次减少0.5kg碳排放
                break;
            case "地铁":
                earnedPoints = 2; // 乘坐地铁1次积2分
                carbonReduction = 0.5; // 地铁出行1次减少0.5kg碳排放
                break;
            case "步行":
                earnedPoints = (int) Math.ceil(distance * 2); // 步行1公里积2分
                carbonReduction = distance * 0.2; // 步行1公里减少0.2kg碳排放
                break;
            default:
                earnedPoints = 0;
                carbonReduction = 0;
        }
    }

    // Getters and Setters
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public Date getTravelDate() {
        return travelDate;
    }

    public void setTravelDate(Date travelDate) {
        this.travelDate = travelDate;
    }

    public String getTravelType() {
        return travelType;
    }

    public void setTravelType(String travelType) {
        this.travelType = travelType;
        calculatePointsAndCarbonReduction(); // 当出行方式改变时重新计算积分和碳减排
    }

    public String getStartLocation() {
        return startLocation;
    }

    public void setStartLocation(String startLocation) {
        this.startLocation = startLocation;
    }

    public String getEndLocation() {
        return endLocation;
    }

    public void setEndLocation(String endLocation) {
        this.endLocation = endLocation;
    }

    public double getDistance() {
        return distance;
    }

    public void setDistance(double distance) {
        this.distance = distance;
        calculatePointsAndCarbonReduction(); // 当距离改变时重新计算积分和碳减排
    }

    public int getEarnedPoints() {
        return earnedPoints;
    }

    /**
     * 设置获得的积分
     * 
     * @param earnedPoints 积分值
     */
    public void setEarnedPoints(int earnedPoints) {
        this.earnedPoints = earnedPoints;
    }

    public double getCarbonReduction() {
        return carbonReduction;
    }

    /**
     * 设置减少的碳排放量
     * 
     * @param carbonReduction 碳减排量(kg)
     */
    public void setCarbonReduction(double carbonReduction) {
        this.carbonReduction = carbonReduction;
    }
}
